package com.yunsoft.controller;

import java.util.HashMap;

import org.slf4j.Logger;

import com.yunsoft.util.Constant;
import com.yunsoft.util.StringFunction;

public class BasicController {
	
	
	
	public HashMap<String,Object> returnSuccessData(int Code,String message,Object result){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Code);
		map.put(Constant.RESULT,Constant.SUCCESS);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(Constant.DATAS, "");
		}else{
			map.put(Constant.DATAS, result);
		}
		return map;
	}
	
	public HashMap<String,Object> returnSuccessData(String message,Object result){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Constant.CODE_SUCCESS);
		map.put(Constant.RESULT,Constant.SUCCESS);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(Constant.DATAS, "");
		}else{
			map.put(Constant.DATAS, result);
		}
		return map;
	}
	/**
	 * 返回数据自定义返回的数据值的key值
	 * @param message
	 * @param key
	 * @param result
	 * @return
	 */
	public HashMap<String,Object> returnSuccessData(String message,String key,Object result){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Constant.CODE_SUCCESS);
		map.put(Constant.RESULT,Constant.SUCCESS);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(key, "");
		}else{
			map.put(key, result);
		}
		return map;
	}
	
	
	
	public HashMap<String,Object> returnSuccessData(String message,Object result,long requstTime){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Constant.CODE_SUCCESS);
		map.put(Constant.RESULT,Constant.SUCCESS);
		map.put(Constant.REQUSTTIME,requstTime);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(Constant.DATAS, "");
		}else{
			map.put(Constant.DATAS, result);
		}
		return map;
	}
	
	
	public HashMap<String,Object> returnFailData(String message,Object result){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Constant.CODE_ERROR);
		map.put(Constant.RESULT,Constant.FAILED);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(Constant.DATAS, "");
		}else{
			map.put(Constant.DATAS, result);
		}

		return map;
	}
	
	public HashMap<String,Object> returnNoData(String message,Object result){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Constant.CODE_NODATA);
		map.put(Constant.RESULT,Constant.FAILED);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(Constant.DATAS, "");
		}else{
			map.put(Constant.DATAS, result);
		}
		return map;
	}
	
	public HashMap<String,Object> returnErrorMessage(String message,Object result){
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put(Constant.CODE,Constant.CODE_ERROR);
		map.put(Constant.RESULT,Constant.FAILED);
		map.put(Constant.MESSAGE, message);
		if(result instanceof String&&StringFunction.isNull(result)){
			map.put(Constant.DATAS, null);
		}else{
			map.put(Constant.DATAS, result);
		}
		
		return map;
	}
}
